package com.common.InterceptorChain;

import java.util.ArrayList;
import java.util.List;

/**
 * 业务处理器链: 非线程安全
 * @author 大忽悠
 * @create 2022/9/24 17:42
 */
public class BusinessInterceptorChain {
    private List<BusinessInterceptor> businessInterceptors=new ArrayList<>();

    public void interceptor(BusinessContext businessContext){
        for (BusinessInterceptor businessInterceptor : businessInterceptors) {
            if (!businessInterceptor.interceptor(businessContext)) {
                        return;
            }
        }
    }

    public void addInterceptor(BusinessInterceptor businessInterceptor){
        businessInterceptors.add(businessInterceptor);
    }

    public void addInterceptorByIndex(BusinessInterceptor businessInterceptor,int index){
        businessInterceptors.add(index,businessInterceptor);
    }

    public void removeInterceptor(BusinessInterceptor businessInterceptor){
        businessInterceptors.remove(businessInterceptor);
    }
}
